﻿package kr.pfg.pfgTracer.view.list
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import kr.pfg.pfgTracer.model.event.VListItemSelectEvent;
	import kr.pfg.pfgTracer.model.vo.EchoClient;
	
	public class VListSpace extends Sprite
	{
		private var tetBox: Sprite;
		
		public function VListSpace()
		{
			tetBox = new Sprite();
			addChild ( tetBox );	
			
			this.init();
		}
		
		private var txtItem: VListItem;		
		public function inputItem( data: Array ): void
		{
			var n: uint = data.length;
			if ( tetBox.numChildren > 0 )
			{
				reset ( n - 1 );
			}	
			while ( n-- )
			{
				txtItem = new VListItem();
				txtItem.y = n * 30;
				txtItem.addEventListener( MouseEvent.CLICK, clickHandler );
				txtItem.setData( data[n], data[n].key )
				tetBox.addChild ( txtItem);
			}
		}
		
		private function clickHandler ( e: MouseEvent ): void
		{
			var data: Object = new Object();
			data.fileName 	= e.currentTarget.fileName;
			data.key 		= e.currentTarget.key; 
			this.dispatchEvent( new VListItemSelectEvent ( VListItemSelectEvent.VLIST_ITEM_CLICK, data, true ) );
		}
		
		
	
		private function reset( n: uint ): void
		{
			while ( n-- )
			{
				tetBox.removeChildAt( n );
			}
			
		}
	}
}